1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class MonsterSpawner : MonoBehaviour {
6
7     
public GameObject monster;
8     
public float spawnDelay;
9
10     
bool canSpawn;
11
12     
void Start () {
13         canSpawn =
true;
14     }
15     
16     
void Update () {
17         
if (canSpawn)
18         {
19             StartCoroutine(
"SpawnMonster");
20         }
21     }
22
23     IEnumerator SpawnMonster()
24     {
25         Instantiate(monster, transform.position, Quaternion.identity);
// spawns the jumping fish
26         canSpawn =
false;
27
28         
yield return new WaitForSeconds(spawnDelay);
29
30         canSpawn =
true;
31     }
32 }


Instantiate(monster, transform.position, Quaternion.identity); spawns the jumping fish




Trò chơi bắn đạn đơn giản sử dụng Unity 13.467 lượt xem

Gõ tìm kiếm nhanh...